/*
 * Copyright (c) Huawei Technologies Co., Ltd. 2025. All rights reserved.
 * Global Trust Authority is licensed under the Mulan PSL v2.
 * You can use this software according to the terms and conditions of the Mulan PSL v2.
 * You may obtain a copy of Mulan PSL v2 at:
 *     http://license.coscl.org.cn/MulanPSL2
 * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR
 * PURPOSE.
 * See the Mulan PSL v2 for more details.
 */


use sea_orm::entity::prelude::*;
use serde::Serialize;

#[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq, Serialize, Default)]
#[sea_orm(table_name = "t_cert_revoked_list")]
pub struct Model {
    #[sea_orm(column_name = "id", primary_key, auto_increment = false)]
    pub id: String,
    #[sea_orm(column_name = "issuer")]
    pub issuer: Option<String>,
    #[sea_orm(column_name = "serial_num")]
    pub serial_num: Option<String>,
    #[sea_orm(column_name = "user_id")]
    pub user_id: Option<String>,
    #[sea_orm(column_name = "cert_revoked_date")]
    pub cert_revoked_date: Option<i64>,
    #[sea_orm(column_name = "cert_revoked_reason")]
    pub cert_revoked_reason: Option<String>,
    #[sea_orm(column_name = "crl_id")]
    pub crl_id: String,
    #[sea_orm(column_name = "signature")]
    pub signature: Option<Vec<u8>>,
    #[sea_orm(column_name = "key_version")]
    pub key_version: Option<String>,
    #[sea_orm(column_name = "key_id")]
    pub key_id: Option<String>,
    #[sea_orm(column_name = "valid_code")]
    pub valid_code: Option<i32>,
}

#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
pub enum Relation {
    #[sea_orm(
        belongs_to = "super::cert_info::Entity",
        from = "Column::Id",
        to = "super::cert_info::Column::Id"
    )]
    CertInfo,
}

impl Related<super::cert_info::Entity> for Entity {
    fn to() -> RelationDef {
        Relation::CertInfo.def()
    }
}

impl ActiveModelBehavior for ActiveModel {}
